﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HomeWork9
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                String url = richTextBox1.Text;
                WebRequest request = WebRequest.Create(url);//获取页面内容
                request.Timeout = 200000;//20秒超时 
                WebResponse response = request.GetResponse();
                Stream resStream = response.GetResponseStream();
                StreamReader sr = new StreamReader(resStream);
                string tempstr = sr.ReadToEnd();//获取页面html代码
            //richTextBox1.Text = tempstr;
            MatchCollection c1 = Regex.Matches(tempstr, @"[1][3,4,5,7,8][0-9]{9}");
            foreach (Match match in c1) {
                richTextBox2.Text += match.ToString() + Environment.NewLine;
            }
            MatchCollection c2 = Regex.Matches(tempstr, @"\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}");
            foreach (Match match in c2)
            {
                richTextBox3.Text += match.ToString()+  Environment.NewLine ;
            }
            }
            catch
            {
                label1.Text = "该URL不可用，请重新输入";
            }
        }
    }
}
